package org.wdcode.base.bean.impl;

/**
 * 继承BaseEntityBean,封装了state
 * @author WD
 * @since JDK6
 * @version 1.0 2009-11-23
 */
public abstract class BaseStateEntityBean extends BaseEntityBean {
	// 状态
	private Short	state;

	/**
	 * 构造方法
	 */
	public BaseStateEntityBean() {
		super();
	}

	/**
	 * 构造方法 使用ID构造一个实体
	 * @param id ID
	 */
	public BaseStateEntityBean(int id) {
		super(id);
	}

	/**
	 * 构造方法 使用ID、名称构造一个实体
	 * @param id ID
	 * @param name 名称
	 */
	public BaseStateEntityBean(int id, String name) {
		super(id, name);
	}

	/**
	 * 构造方法 使用ID、名称和状态构造一个实体
	 * @param id 主键ID
	 * @param name 名称
	 * @param state 状态
	 */
	public BaseStateEntityBean(int id, String name, Short state) {
		super(id, name);
		this.state = state;
	}

	/**
	 * 获得状态
	 * @return 状态
	 */
	public final Short getState() {
		return this.state;
	}

	/**
	 * 设置状态
	 * @param state 状态
	 */
	public final void setState(Short state) {
		this.state = state;
	}

	/**
	 * 清除属性值
	 */
	@Override
	public void clear() {
		super.clear();
		this.state = null;
	}

	/**
	 * 获得hashCode
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((state == null) ? 0 : state.hashCode());
		return result;
	}

	/**
	 * 判断对象是否相等
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		BaseStateEntityBean other = (BaseStateEntityBean) obj;
		if (state == null) {
			if (other.state != null)
				return false;
		} else if (!state.equals(other.state))
			return false;
		return true;
	}
}
